from sqlalchemy import Column, Integer, String, Text, DateTime, ForeignKey
from sqlalchemy.orm import relationship, declarative_base
import datetime

Base = declarative_base()

class Software(Base):
    __tablename__ = "software"
    id = Column(Integer, primary_key=True)
    name = Column(String(255), nullable=False)
    version = Column(String(64))
    description = Column(Text)
    category = Column(String(128))
    license = Column(String(128))
    update_time = Column(DateTime, default=datetime.datetime.utcnow)
    source = Column(String(255))

    links = relationship("DownloadLink", back_populates="software")

class DownloadLink(Base):
    __tablename__ = "download_link"
    id = Column(Integer, primary_key=True)
    software_id = Column(Integer, ForeignKey("software.id"))
    url = Column(Text, nullable=False)
    link_type = Column(String(16))  # ed2k, magnet
    file_format = Column(String(16))  # zip, rpm, deb, src
    software = relationship("Software", back_populates="links")

class Feedback(Base):
    __tablename__ = "feedback"
    id = Column(Integer, primary_key=True)
    content = Column(Text, nullable=False)
    contact = Column(String(255))
    ip_address = Column(String(64))
    create_time = Column(DateTime, default=datetime.datetime.utcnow)
